/**
 * 
 */
package br.ufpb.sistcomp.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

/**
 * Facade to the database.
 * 
 * @author Diego Sousa, www.diegosousa.com
 * @version 1.0
 * @since 25/01/2012
 * 
 *        Copyright (C) 2012 SistComp Empresa Jr.
 */

public class FacadeDatabase {

	private ManagerDatabase managerDatabase;
	private Context context;

	public FacadeDatabase(Context context) {
		this.context = context;
	}

	public void createDatabaseAndTables() {
		this.managerDatabase = new ManagerDatabase(this.context);
	}

	public void runScript(String[] script) {

		SQLiteDatabase sqLiteDatabase = managerDatabase.getWritableDatabase();
		this.managerDatabase.runScript(sqLiteDatabase, script);
	}

	public void upgrade(int newVersion) {
		
		InformationDatabase.VERSION_DATABASE = newVersion;
		createDatabaseAndTables();		
	}

	public void openDataBase() {
		SQLiteDatabase sqLiteDatabase = managerDatabase.getWritableDatabase();
		this.managerDatabase.onOpen(sqLiteDatabase);
	}

	public void closeDatabase() {
		this.managerDatabase.close();
	}

}
